package com.crm.jdy.service.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.dto.ClientChargeInfoDto;
import com.crm.jdy.common.pojo.ClientChargeInfo;
import com.crm.jdy.common.mapper.ClientChargeInfoMapper;
import com.crm.jdy.common.pojo.ClientInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**   
 * @Description:(客户-联系人服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class ClientChargeInfoServiceImpl  extends ServiceImpl<ClientChargeInfoMapper,ClientChargeInfo> implements ClientChargeInfoService  {

    @Autowired
    ClientChargeInfoMapper clientChargeInfoMapper;

    @Override
    public PageInfo<ClientChargeInfo> seleteClientChargeInfoPageInfo(ClientChargeInfoDto clientinfo) {
        PageHelper.startPage( clientinfo.getCurrentPage(),clientinfo.getPageSize());
        List<ClientChargeInfo> bookList = clientChargeInfoMapper.seleteClientInfo(clientinfo);
        PageInfo<ClientChargeInfo> pageInfo = new PageInfo<ClientChargeInfo>(bookList);
        return pageInfo;
    }

    @Override
    public boolean updateClientChargeInfo(ClientChargeInfo clientinfo) {
        return clientChargeInfoMapper.updateById(clientinfo) > 0;
    }

    @Override
    public boolean addClientChargeInfo(ClientChargeInfo clientinfo) {
        LambdaQueryWrapper<ClientChargeInfo> lambda = new QueryWrapper<ClientChargeInfo>().lambda()
                .eq(ClientChargeInfo::getChargePhone, clientinfo.getChargePhone());
        ClientChargeInfo clientInfo = clientChargeInfoMapper.selectOne(lambda);
        if( clientInfo !=null && ObjectUtils.isEmpty(clientInfo)){
            return false;
        }else{
            return clientChargeInfoMapper.insert(clientinfo) > 0;
        }
    }

    @Override
    public boolean removeClientChargeInfo(String chargeId) {
        return clientChargeInfoMapper.deleteById(chargeId) > 0;
    }


}